﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Directory.Web
{
	public partial class AdminLogin : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if (Page.User.Identity.IsAuthenticated)
			{
				RedirectPage();
			}
		}

		protected void btnLogin_Click(object sender, EventArgs e)
		{
			if (WebUtil.TryLogIn(tbName.Text.Trim(), tbPassword.Text.Trim(), false))
			{
				Response.Redirect("~/AdminLogin.aspx");
			}
			else
			{
				this.lbMsg.Text = "帐号或密码错误！";
			}
		}

		private void RedirectPage()
		{
			if (WebUtil.IsCurrentUserInRole(WebSettings.GetInstance().CategoryAdminRole) || WebUtil.IsCurrentUserInRole(WebSettings.GetInstance().RootCategoryAdminRole))
			{
				Response.Redirect("~/Admin/categorymgr.aspx");
			}
			else if (WebUtil.IsCurrentUserInRole(WebSettings.GetInstance().SiteSettingsAdminRole))
			{
				Response.Redirect("~/Admin/MessageManage.aspx");
			}
			else if (WebUtil.IsCurrentUserInRole(WebSettings.GetInstance().SecurityAdminRole))
			{
				Response.Redirect("~/Admin/permitmgr.aspx");
			}
			else
			{
				Response.Redirect("~/User/UserInfo.aspx");
			}
		}
	}
}
